/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.util.ArrayList;
import java.util.Scanner;

/**
* @author Anjori
 */
public class Token extends Board {

    private Scanner in = new Scanner(System.in);
    private Player owner;
    private Square position;
    private int ID;
    private int currentPos;
    //end of instance variables

    public Token(int m, ArrayList<Integer> n, ArrayList<Integer> o, Player p, int i) {
        super(m, n, o);
        this.owner = p;
        this.ID = i;
        position = squares.get(0);
        currentPos = 1;
    }//end of Token constructor

    public Player getOwner() {
        return this.owner;
    }//end of method getOwner

    public void setPosition(Square position1) {
        this.position = position1;
    }//end of method setPosition
    
    public void bump() {
        
        System.out.println(owner.getName() + " just got bumped back to square 1!");
        this.setPosition(squares.get(0));
    }
    
    public void moveCmpToken(int n, String direction) {

        currentPos = this.getPosition().getNumber();
                
                if(direction.equalsIgnoreCase("f")) {
                    
                    System.out.println("Moving forwards...");
                    n = n + currentPos;
                    if (checkUps(n)) 
                    {
                        n = findEnd(n);
                    }
                    if (checkDowns(n)) {
                        n = findEnd(n);
                    }
                    this.setPosition(squares.get(n-1));
                 }
                else if(direction.equalsIgnoreCase("b")) {

                    System.out.println("Moving backwards...");
                    if(currentPos > n)
                        n = currentPos - n;
                    else
                        n = n - currentPos;

                    if (checkUps(n)) 
                    {
                        n = findEnd(n);
                    }
                    if (checkDowns(n)) {
                        n = findEnd(n);
                    }
                    this.setPosition(squares.get(n-1));
                
            }
  
    }

    public void printMove(int move, Player p)//sets the owner of a square and prints the move
    {
        squares.get(move).setOwner(this.getOwner()); //set the new owner of a square   

    }//end of method printMove

    public Square getPosition() {
        return position;
    }//end of method getPosition

}//end of class Token
